package com.xt.base.acegi;

import org.acegisecurity.providers.encoding.PasswordEncoder;
import org.springframework.dao.DataAccessException;

import com.xt.base.util.StringUtil;

public class AcegiPasswordEncoder implements PasswordEncoder {

	public String encodePassword(String rawPass, Object salt)
			throws DataAccessException {
		StringUtil.makePassword(rawPass);
		return rawPass;

	}

	

    /**
     * <p>Validates a specified "raw" password against an encoded password.</p>
     *  <P>The encoded password should have previously been generated by {@link #encodePassword(String,
     * Object)}. This method will encode the <code>rawPass</code> (using the optional <code>salt</code>),  and then
     * compared it with the presented <code>encPass</code>.</p>
     *  <p>For a discussion of salts, please refer to {@link #encodePassword(String, Object)}.</p>
     *
     * @param encPass a pre-encoded password
     * @param rawPass a raw password to encode and compare against the pre-encoded password
     * @param salt optionally used by the implementation to "salt" the raw password before encoding. A
     *        <code>null</code> value is legal.
     *
     * @return true if the password is valid , false otherwise
     *
     * @throws DataAccessException DOCUMENT ME!
     */
    public boolean isPasswordValid(String encPass, String rawPass, Object salt)
			throws DataAccessException {
        String pass1 = "" + encPass;
        String pass2 = StringUtil.makePassword(rawPass);
        return pass1.equals(pass2);		
	}

}
